package logic

import (
	"common/model"
	"common/utils"
	"context"
	"errors"
	"fmt"
	"opd_server/proto/opd"
	"time"
)

func (o OpdService) DoctorInfo(ctx context.Context, req *opd.DoctorInfoRequest) (resp *opd.DoctorInfoResponse, err error) {
	var doctor model.Doctors
	info, err := doctor.ByInfo(req.DoctorId)
	if err != nil {
		return nil, err
	}
	if info.Id == 0 {
		return nil, errors.New("没有该医生")
	}

	opdKey := time.Now().Format("2006-01-02")
	key := fmt.Sprintf("opd:%s:%d:%d", opdKey, 1, req.DoctorId)
	key1 := fmt.Sprintf("opd:%s:%d:%d", opdKey, 2, req.DoctorId)
	lRange, err := utils.GetRedisListLen(key)
	if err != nil {
		return nil, err
	}
	lRange1, err := utils.GetRedisListLen(key1)
	if err != nil {
		return nil, err
	}

	workTime := info.StartWorkDate.Format("2006-01-02")

	fmt.Println(lRange, lRange1, 11111111111)
	resp = &opd.DoctorInfoResponse{
		DoctorInfo: &opd.DoctorInfo{
			DoctorName:          info.DoctorName,
			DoctorAge:           info.DoctorAge,
			DoctorSex:           int64(info.Sex),
			EducationDegree:     info.EducationDegree,
			StartWorkDate:       workTime,
			GraduatedUniversity: info.GraduatedUniversity,
			DoctorTitle:         info.Title,
			Department:          info.Department,
			Registered:          lRange + lRange1,
		},
	}
	return resp, nil
}
